import axios from '@/utils/request'
export default {
  HuifuAccount: {
    list: {
      query: {
        '@filter': `entity.getId() > 1`
      },
      disabled_actions: ['lines'],
      list_filter: {
        'user.username': '账号',
        'store.id': () => {
          return axios
            .get('/manage/stores')
            .then(res =>
              Object.assign({ __label: '门店' },
                ...res.data.map(v => { return { [v.id]: v.name } })
              )
            )
        }
      },
      list_display: [
        'id',
        'store',
        'user',
        { property: 'huifuId', label: '汇付客户ID ' },
        { property: 'autoWithdraw', label: '自动提现', editable: true },
        { property: 'indvBaseInfo.name', label: '姓名' },
        // { property: 'indvBaseInfo.cert_no', label: '证件号' },
        { property: 'indvBaseInfo.mobile_no', label: '手机号' },
        {
          property: 'cardInfo.card_no',
          label: '提现银行卡'
        },
        {
          property: 'balance',
          label: '汇付钱包余额',
          component: {
            props: ['record'],
            data() {
              return {
                amount: '点击查询'
              }
            },
            created() {
              // axios.get(`/manage/huifu-accounts/${this.record.id}/balance`).then((res) => {
              //   console.log('汇付balance')
              //   this.amount = res.data[0].balance_amt
              // })
            },
            render(h) {
              return <div>
                <p onClick={() => {
                  axios.get(`/manage/huifu-accounts/${this.record.id}/balance`).then((res) => {
                    console.log('汇付balance')
                    this.amount = res.data[0].balance_amt
                  })
                }}>{this.amount}</p>
                <p onClick={() => {
                  if (this.amount === '点击查询' || this.amount === 0) {
                    this.$message.error('不符合转账条件')
                  } else {
                    axios.post(`/manage/huifu-accounts/${this.record.id}/transfer/to/1/amount/${this.amount}
                    `).then((res) => {
                      console.log(res)
                    })
                  }
                }}
                >转到商户号</p>
              </div>
            }
          }
        }
      ]
    },
    form: {
      fields: [
        // { property: 'huifuId', field_options: { label: '汇付客户ID' }}
      ]
    }
  }
}

